home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Multiprocessing 2.1v2 SDK / Sample Code / MP Sort Picts 12⁄04⁄99 / sources / MPSortPicts.h < prev   
Encoding:
Text File  |  1998-11-02  |  4.4 KB  |  207 lines  |  [TEXT/CWIE]

  1. /*
  2.  *    File:    SortPicts.h
  3.  *    -------------------
  4.  *    
  5.  *
  6.  *
  7.  */
  8.  
  9.  
  10. //#include "SortPictsPrecompile.c"
  11.  
  12. #ifndef __SortPicts__
  13. #define __SortPicts__
  14.  
  15. class    SortPicts;
  16.  
  17. #include "Window.h"
  18. #include "Sprocket.h"
  19. #include "Multiprocessing.h"
  20.  
  21. #include <Threads.h>
  22. #include <QDOffscreen.h>
  23. #include <Sound.h>
  24. //#include <LowMem.h>
  25.  
  26. #define kUpdateInterval 5;
  27.  
  28. /*
  29.  *    QuickSort #define
  30.  */
  31. #define    kPivotCutoff    25
  32.  
  33. typedef    void    (*SortFuncPtr)( SortPicts *sortPicts);
  34. typedef    void    (*UpdateFuncPtr)( SortPicts *sortPicts);
  35.  
  36. typedef    unsigned char    SortPixel;
  37. typedef    SortPixel        *SortPixelPtr;
  38. typedef    SortPixelPtr    *SortPixelHandle;
  39.  
  40. typedef    long            SortData;
  41. typedef    SortData        *SortDataPtr;
  42. typedef SortDataPtr        *SortDataHandle;
  43.  
  44. #define    kYieldTime                    4
  45. #define    kWindPictRectVoffset        0
  46.  
  47. /* The names of windows to open at startup time */
  48. #define    kDefaultWindowResource        100
  49.  
  50. #include "Window.h"
  51.  
  52. class    SortPicts : public TWindow {
  53. public:
  54.     
  55.     
  56.     GWorldPtr            sortGWorld;
  57.     PixMapHandle        sortPixmap;
  58.     SortPixelPtr        sortPixels;
  59.     SortDataPtr            sortData;
  60.     SortDataHandle        sortHandle;
  61. static long                gNumWindowsCreated;
  62. static short            gPrefsRef;
  63.  
  64.     long                N;
  65.  
  66.     long                pictWidth;
  67.     long                pictHeight;
  68.     long                pictRowBytes;
  69.     
  70.     Rect                updateRect;
  71.     Rect                sortRect;
  72.     Rect                copyBitsRect;
  73.     Rect                windPictRect;
  74.  
  75.     long                low, high;
  76.  
  77.     SortFuncPtr            sortFunc;
  78.     UpdateFuncPtr        updateFunc;
  79.  
  80.     PicHandle            sortPict;
  81.     WindowPtr            me;
  82.  
  83.     long                randomSeed;
  84.  
  85.  
  86.     long                startTime;
  87.     long                newUnitCount;
  88.     long                unitCount;
  89.  
  90.     ThreadID            threadInfo;
  91.     
  92.     Boolean                coplandTask;
  93. //    TaskName            myTaskName;
  94.     MPTaskID            myTaskID;
  95.     MPCriticalRegionID    sortBlitterBusy;
  96.     unsigned long        updateTime;
  97.     
  98.     long                horiz;
  99.     long                vert;
  100.     long                lastHorizLeft;
  101.     long                lastHorizRight;
  102.     long                pixelVert;
  103.     
  104. public:
  105.                          SortPicts();
  106.                          SortPicts( ConstStr255Param name);
  107.     virtual             ~SortPicts();
  108.  
  109.     virtual    void        Idle(EventRecord *anEvent);
  110.     virtual WindowPtr    MakeNewWindow(WindowPtr behindWindow);
  111.     virtual    void        AdjustCursor(EventRecord * anEvent);
  112.     virtual void        Activate(Boolean activating);
  113.     virtual void        Draw(void);
  114.     virtual    void        Drag(Point startPoint);
  115.  
  116. //    virtual void        Click(EventRecord * anEvent);
  117.     virtual    void        KeyDown(EventRecord * anEvent);
  118.  
  119.     virtual void        AdjustForNewWindowSize(Rect * oldRect,Rect * newRect);
  120.  
  121.     virtual    Boolean        Close(void);
  122.     
  123.     virtual    OSErr        HandleDrag(DragTrackingMessage dragMessage,DragReference theDrag);
  124.     virtual    OSErr        HandleDrop(DragReference theDrag);
  125.  
  126.     Boolean                PrepareGWorld( ConstStr255Param pictName);
  127.     
  128.     Boolean                LoadSortPicture( ConstStr255Param pictName);
  129.     void                ReleaseSortPicture( void);
  130.     Boolean                MakeSortGWorld( void);
  131.     Boolean                AllocSortData( void);
  132.     void                CopyFromSortData( void );
  133.     void                ReleaseSortData( void);
  134.     void                MakeSortData( void);
  135.     void                UseSortData( void);
  136.     void                UnuseSortData( void);
  137.     void                InitializeSortWindowRect( ConstStr255Param pictName);
  138.     void                OpenDefaultSortWindows( void);
  139.     void                SelectRandomPicture( void);
  140.     
  141.     Str255                sortPictsName;
  142.     long                Random( long num);
  143.     long                RandomPixel( void);
  144.     void                SetSortItem( long index, long data);
  145.     void                ExchangeSortItem( long one, long theOther);
  146.     void                Scramble( void);
  147.  
  148.     void                UseUpdateFunc( UpdateFuncPtr updateFunc);
  149.     void                Update( void);
  150.     void                UpdateScramble( void);
  151.     void                UpdateSortPict( void);
  152.     
  153.     void                Entry( void);
  154.     void                MakeThreaded( void);
  155.     void                Yield( void);
  156.     void                CalculateNewUnitCount( void);
  157.     
  158.     void                UseSortFunc( SortFuncPtr sortFunc);
  159.     void                Sort( void);
  160.  
  161.     void                QSort( void);
  162.     void                ChooseMedian( long a, long b, long c);
  163.     void                QuickSortEngine( long left, long right);
  164.  
  165.     void                HeapSort( void);
  166.     void                BuildHeap( void);
  167.     void                Heapify( long size, long index);
  168.     
  169.     void                ShellSort( void);
  170. };
  171.  
  172. void    UpdateScramble( SortPicts *sortPicts);
  173. void    UpdateSortPict( SortPicts *sortPicts);
  174. void    QSort( SortPicts *sortPicts);
  175. void    HeapSort( SortPicts *sortPicts);
  176. void    ShellSort( SortPicts *sortPicts);
  177.  
  178. pascal    voidPtr    SortPictsThreadEntry( void *there);
  179.  
  180.  
  181. //    menus defined by SortPicts
  182.  
  183. #ifndef        _STANDARDMENUS_
  184. #include    "StandardMenus.h"
  185. #endif
  186.  
  187. #define    mSprocketFileMenu                256
  188. #define        iNewSortingPict                1
  189. #define        iCloseWindow                2
  190. #define        iQuitSortPicts                4
  191.  
  192. #define    mSortAlgorithm                    257
  193. #define        iQuickSort                    1
  194. #define        iShellSort                    2
  195. #define        iHeapSort                    3
  196. #define        iRandomSort                    5
  197. #define        iUseCoplandTasks            7
  198.  
  199. #define    mPictureMenu                    258
  200.  
  201. #define    kAboutBoxFor68K                    256
  202. #define    kAboutBoxForPowerPC                257
  203. #define        iCreditsButton                    2
  204.  
  205. #define    kCreditsBox                        258
  206.  
  207. #endif